﻿
namespace LS.Nc6.Application;
public class LogEventSubscriber : IEventSubscriber
{
    public LogEventSubscriber(IServiceProvider services)
    {
        Services = services;
    }

    public IServiceProvider Services { get; }

    [EventSubscribe("Create:OpLog")]
    public async Task CreateOpLog(EventHandlerExecutingContext context)
    {
        using var scope = Services.CreateScope();
        var _repository = scope.ServiceProvider.GetRequiredService<SysOperateLogService>();
        var log = (SysOperateLogEntity)context.Source.Payload;
        await _repository.InsertAsync(log);
    }

    [EventSubscribe("Create:LoginLog")]
    public async Task CreateExLog(EventHandlerExecutingContext context)
    {
        
        using var scope = Services.CreateScope();
        //var _repository = scope.ServiceProvider.GetService<SysLoginLogService>();
        var _repository = scope.ServiceProvider.GetRequiredService<SysLoginLogService>();
        var log = (SysLoginLogEntity)context.Source.Payload;
        await _repository.InsertAsync(log);
    }
 
}